import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DemoJTextField extends JFrame implements ActionListener
{
private JTextField jTFInput1,jTFHasil;
private JButton btnJumlah;

public static void main (String args [])
{
DemoJTextField frame=new DemoJTextField();
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

public DemoJTextField()
{
setTitle("Program Luas Bujur Sangkar");
setBackground(Color.blue);
setForeground(Color.black);

JPanel p1=new JPanel();
p1.setLayout(new FlowLayout());
p1.add(new JLabel("Masukkan sisi"));
p1.add(jTFInput1=new JTextField(5));
p1.add(new JLabel("Luas"));
p1.add(jTFHasil=new JTextField(5));
jTFHasil.setEditable(false);

JPanel p2=new JPanel();
p2.setLayout(new FlowLayout());
p2.add(btnJumlah=new JButton("Hitung Luas"));

getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1, BorderLayout.CENTER);
getContentPane().add(p2, BorderLayout.SOUTH);

btnJumlah.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
if (e.getSource()==btnJumlah)
	{
	int bilangan1=(Integer.parseInt(jTFInput1.getText().trim()));
	int hasil=bilangan1*bilangan1;
	
	jTFHasil.setText(String.valueOf(hasil));
	}
		}
			}
